#include <stdlib.h> 
#include <stdio.h>
#include <SDL/SDL.h>
#include<SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>






 int main( int argc, char *argv[] ) 
{



SDL_Surface *ecran = NULL, *perso = NULL , *background = NULL ;
 



SDL_Rect position_perso; // positionnement x et y //
SDL_Rect position_background ;
 






 SDL_Event event;
 
int echap=1;
 int i;


 position_background.x =0;
 position_background.y = 0;
 position_perso.x = 200;
 position_perso.y = 250;
 

SDL_Init(SDL_INIT_VIDEO);

 




ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
 SDL_WM_SetCaption("jeux tombour", NULL);



background = IMG_Load("background.gif");
perso=IMG_Load("perso.png"); 


 Mix_OpenAudio(22050, AUDIO_S16SYS,2,200) ;
  


   Mix_Chunk *son;//Créer un pointeur pour stocker un .WAV
   
son = Mix_LoadWAV("1.wav"); //Charger un wav dans un pointeur
  


SDL_EnableKeyRepeat(100,100);







while(echap) 
{ 

    
SDL_WaitEvent(&event);
        switch(event.type)
        {
	 case SDL_MOUSEBUTTONUP:
Mix_PlayChannel(1, son, 0);//Joue le son 1 sur le canal 1 ; une fois
		
		break;        
	case SDL_KEYDOWN:
           switch(event.key.keysym.sym)
      { 
            case SDLK_UP:
       // Flèche haut
            position_perso.y=position_perso.y-10;                            
 break;
 case SDLK_DOWN: 
// Flèche bas 
  position_perso.y=position_perso.y+10;
   
 break;
 case SDLK_RIGHT:
 // Flèche droite
 position_perso.x=position_perso.x+10;
 
 i++;
 break;
 case SDLK_LEFT: 
//Flèche gauche
 position_perso.x=position_perso.x-10;
 
 break;
 
 case SDLK_x:
// si on appuie sur x on va quitter le jeux//
 echap=0;
 break;
 
} 


 


}



 
SDL_BlitSurface(background, NULL, ecran, &position_background);
SDL_BlitSurface(perso,NULL, ecran, &position_perso);
SDL_Flip(ecran); 




}
 






Mix_FreeChunk(son);//Libération du son 1

Mix_CloseAudio(); //Fermeture de l'API

 SDL_FreeSurface(perso);
 SDL_FreeSurface(background);
 

 
SDL_Quit();




 return EXIT_SUCCESS;



 }
